Constants

INPUT_GET

INPUT_GET = 1

INPUT_POST

INPUT_POST = 2

INPUT_GP

INPUT_GP = 3

INPUT_GPC

INPUT_GPC = 7

Methods

explode()

explode(string  $separator, string  $string) : array

A wrapper for PHP's explode() that does not throw a warning when the separator does not exist in the string

Parameters

string $separator

Separator string

string $string

The string to explode

Returns

array —

Exploded string. Still an array if there's no separator in the string

setcookie()

setcookie(string  $name, string  $value, int  $exp, bool  $http_only = true) : mixed

Helper method to set a cookie with the current path and host settings

Parameters

string $name

Cookie name

string $value

Cookie value

int $exp

Expiration time

bool $http_only

HTTP Only

Returns

mixed —

check_email()

check_email(string  $email, bool  $dns_check = true) : bool

E-mail address validation.

Parameters

string $email

Email address

bool $dns_check

True to check dns

Returns

bool —

True on success, False if address is invalid

check_ip()

check_ip(string  $ip) : bool

Validates IPv4 or IPv6 address

Parameters

string $ip

IP address in v4 or v6 format

Returns

bool —

True if the address is valid

rep_specialchars_output()

rep_specialchars_output(string  $str, string  $enctype = '', string  $mode = '', bool  $newlines = true) : string

Replacing specials characters to a specific encoding type

Parameters

string $str

Input string

string $enctype

Encoding type: text|html|xml|js|url

string $mode

Replace mode for tags: show|remove|strict

bool $newlines

Convert newlines

Returns

string —

The quoted string

get_input_string()

get_input_string(string  $fname, int  $source, bool  $allow_html = false, string  $charset = null) : string

Read input value and make sure it is a string.

Parameters

string $fname

Field name to read

int $source

Source to get value from (see self::INPUT_*)

bool $allow_html

Allow HTML tags in field value

string $charset

Charset to convert into

Returns

string —

Request parameter value

get_input_value()

get_input_value(string  $fname, int  $source, bool  $allow_html = false, string  $charset = null) : string|array|null

Read request parameter value and convert it for internal use Performs stripslashes() and charset conversion if necessary

Parameters

string $fname

Field name to read

int $source

Source to get value from (see self::INPUT_*)

bool $allow_html

Allow HTML tags in field value

string $charset

Charset to convert into

Returns

string|array|null —

Request parameter value or NULL if not set

parse_input_value()

parse_input_value(string  $value, bool  $allow_html = false, string  $charset = null) : string

Parse/validate input value. See self::get_input_value() Performs stripslashes() and charset conversion if necessary

Parameters

string $value

Input value

bool $allow_html

Allow HTML tags in field value

string $charset

Charset to convert into

Returns

string —

Parsed value

request2param()

request2param(int  $mode = null, string  $ignore = 'task|action', bool  $allow_html = false) : array

Convert array of request parameters (prefixed with _) to a regular array with non-prefixed keys.

Parameters

int $mode

Source to get value from (GPC)

string $ignore

PCRE expression to skip parameters by name

bool $allow_html

Allow HTML tags in field value

Returns

array —

Hash array with all request parameters

html_identifier()

html_identifier(string  $str, bool  $encode = false) : mixed

Convert the given string into a valid HTML identifier Same functionality as done in app.js with rcube_webmail.html_identifier()

Parameters

string $str

String input

bool $encode

Use base64 encoding

Returns

mixed —

mod_css_styles()

mod_css_styles(string  $source, string  $container_id, bool  $allow_remote = false, string  $prefix = '') : string

Replace all css definitions with #container [def] and remove css-inlined scripting, make position style safe

Parameters

string $source

CSS source code

string $container_id

Container ID to use as prefix

bool $allow_remote

Allow remote content

string $prefix

Prefix to be added to id/class identifier

Returns

string —

Modified CSS source

parse_css_block()

parse_css_block(string  $style) : array

Explode css style. Property names will be lower-cased and trimmed.

Values will be trimmed. Invalid entries will be skipped.

Parameters

string $style

CSS style

Returns

array —

List of CSS rule pairs, e.g. [['color', 'red'], ['top', '0']]

file2class()

file2class(string  $mimetype, string  $filename) : string

Generate CSS classes from mimetype and filename extension

Parameters

string $mimetype

Mimetype

string $filename

Filename

Returns

string —

CSS classes separated by space

xss_entity_decode()

xss_entity_decode(string  $content) : string

Decode escaped entities used by known XSS exploits.

See http://downloads.securityfocus.com/vulnerabilities/exploits/26800.eml for examples

Parameters

string $content

CSS content to decode

Returns

string —

Decoded string

mem_check()

mem_check(int  $need) : bool

Check if we can process not exceeding memory_limit

Parameters

int $need

Required amount of memory

Returns

bool —

True if memory won't be exceeded, False otherwise

https_check()

https_check(int  $port = null, bool  $use_https = true) : bool

Check if working in SSL mode

Parameters

int $port

HTTPS port number

bool $use_https

Enables 'use_https' option checking

Returns

bool —

True in SSL mode, False otherwise

parse_host()

parse_host(string  $name, string  $host = '') : string

Replaces hostname variables.

Parameters

string $name

Hostname

string $host

Optional IMAP hostname

Returns

string —

Hostname

server_name()

server_name(string  $type = null, bool  $strip_port = true) : string

Returns the server name after checking it against trusted hostname patterns.

Returns 'localhost' and logs a warning when the hostname is not trusted.

Parameters

string $type

The $_SERVER key, e.g. 'HTTP_HOST', Default: 'SERVER_NAME'.

bool $strip_port

Strip port from the host name

Returns

string —

Server name

remote_ip()

remote_ip() : string

Returns remote IP address and forwarded addresses if found

Returns

string —

Remote IP address(es)

remote_addr()

remote_addr() : string

Returns the real remote IP address

Returns

string —

Remote IP address

request_header()

request_header(string  $name) : string|null

Read a specific HTTP request header.

Parameters

string $name

Header name

Returns

string|null —

Header value or null if not available

explode_quoted_string()

explode_quoted_string(string  $delimiter, string  $string) : array

Explode quoted string

Parameters

string $delimiter

Delimiter expression string for preg_match()

string $string

Input string

Returns

array —

String items

strtotime()

strtotime(string  $date, \DateTimeZone  $timezone = null) : int

Improved equivalent to strtotime()

Parameters

string $date

Date string

\DateTimeZone $timezone

Timezone to use for DateTime object

Returns

int —

Unix timestamp

anytodatetime()

anytodatetime(string  $date, \DateTimeZone  $timezone = null) : \DateTime|false

Date parsing function that turns the given value into a DateTime object

Parameters

string $date

Date string

\DateTimeZone $timezone

Timezone to use for DateTime object

Returns

\DateTime|false —

DateTime object or False on failure

clean_datestr()

clean_datestr(string  $date) : string

Clean up date string for strtotime() input

Parameters

string $date

Date string

Returns

string —

Date string

format_datestr()

format_datestr(string  $date, string  $format) : string

Turns the given date-only string in defined format into YYYY-MM-DD format.

Supported formats: 'Y/m/d', 'Y.m.d', 'd-m-Y', 'd/m/Y', 'd.m.Y', 'j.n.Y'

Parameters

string $date

Date string

string $format

Input date format

Returns

string —

Date string in YYYY-MM-DD format, or the original string if format is not supported

idn_to_ascii()

idn_to_ascii(string  $str) : string

Wrapper for idn_to_ascii with support for e-mail address.

Warning: Domain names may be lowercase'd. Warning: An empty string may be returned on invalid domain.

Parameters

string $str

Decoded e-mail address

Returns

string —

Encoded e-mail address

idn_to_utf8()

idn_to_utf8(string  $str) : string

Wrapper for idn_to_utf8 with support for e-mail address

Parameters

string $str

Decoded e-mail address

Returns

string —

Encoded e-mail address

idn_convert()

idn_convert(string  $input, bool  $is_utf = false) : string

Convert a string to ascii or utf8 (using IDNA standard)

Parameters

string $input

Decoded e-mail address

bool $is_utf

Convert by idn_to_ascii if true and idn_to_utf8 if false

Returns

string —

Encoded e-mail address

tokenize_string()

tokenize_string(string  $str, int  $minlen = 2) : array

Split the given string into word tokens

Parameters

string $str

Input to tokenize

int $minlen

Minimum length of a single token

Returns

array —

List of tokens

normalize_string()

normalize_string(string  $str, bool  $as_array = false, int  $minlen = 2) : string|array

Normalize the given string for fulltext search.

Currently only optimized for ISO-8859-1 and ISO-8859-2 characters; to be extended

Parameters

string $str

Input string (UTF-8)

bool $as_array

True to return list of words as array

int $minlen

Minimum length of tokens

Returns

string|array —

Normalized string or a list of normalized tokens

words_match()

words_match(string  $haystack, string  $needle) : bool

Compare two strings for matching words (order not relevant)

Parameters

string $haystack

Haystack

string $needle

Needle

Returns

bool —

True if match, False otherwise

get_opt()

get_opt(array  $aliases = []) : array

Parse commandline arguments into a hash array

Parameters

array $aliases

Argument alias names

Returns

array —

Argument values hash

prompt_silent()

prompt_silent(string  $prompt = "Password:") : string

Safe password prompt for command line from http://blogs.sitepoint.com/2009/05/01/interactive-cli-password-prompt-in-php/

Parameters

string $prompt

Prompt text

Returns

string —

Password

get_boolean()

get_boolean(string  $str) : bool

Find out if the string content means true or false

Parameters

string $str

Input value

Returns

bool —

Boolean value

is_absolute_path()

is_absolute_path(string  $path) : bool

OS-dependent absolute path detection

Parameters

string $path

File path

Returns

bool —

True if the path is absolute, False otherwise

resolve_url()

resolve_url(string  $url) : string

Resolve relative URL

Parameters

string $url

Relative URL

Returns

string —

Absolute URL

random_bytes()

random_bytes(int  $length, bool  $raw = false) : string

Generate a random string

Parameters

int $length

String length

bool $raw

Return RAW data instead of ascii

Returns

string —

The generated random string

bin2ascii()

bin2ascii(string  $input) : string

Convert binary data into readable form (containing a-zA-Z0-9 characters)

Parameters

string $input

Binary input

Returns

string —

Readable output (Base62)

date_format()

date_format(string  $format = null) : string

Format current date according to specified format.

This method supports microseconds (u).

Parameters

string $format

Date format (default: 'd-M-Y H:i:s O')

Returns

string —

Formatted date

parse_socket_options()

parse_socket_options(array  $options, string  $host = null) : mixed

Parses socket options and returns options for specified hostname.

Parameters

array $options

Configured socket options

string $host

Hostname

Returns

mixed —

max_upload_size()

max_upload_size() : int

Get maximum upload size

Returns

int —

Maximum size in bytes

preg_error()

preg_error(array  $error = [], bool  $terminate = false) : bool

Detect and log last PREG operation error

Parameters

array $error

Error data (line, file, code, message)

bool $terminate

Stop script execution

Returns

bool —

True on error, False otherwise

temp_filename()

temp_filename(string  $file_name, bool  $unique = true, bool  $create = true) : string

Generate a temporary file path in the Roundcube temp directory

Parameters

string $file_name

String identifier for the type of temp file

bool $unique

Generate unique file names based on $file_name

bool $create

Create the temp file or not

Returns

string —

temporary file path

remove_subject_prefix()

remove_subject_prefix(string  $subject, string  $mode = 'both') : string

Clean the subject from reply and forward prefix

Parameters

string $subject

Subject to clean

string $mode

Mode of cleaning : reply, forward or both

Returns

string —

Cleaned subject